/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. Camunda licenses this file to you under the Apache License,
 * Version 2.0; you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package su.camunda.operate.delegate;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.el.Expression;
import org.camunda.bpm.engine.impl.el.ExpressionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class SayHelloDelegate implements JavaDelegate {

    private static final Logger LOGGER = LoggerFactory.getLogger(SayHelloDelegate.class);

    private String exp1 = "${dateTime().plusDays(3).toDate()}";
    private String exp2 = "${execution.getProcessInstanceId()}";

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        LOGGER.info("hello {}", execution);
        ExpressionManager expressionManager = ((ProcessEngineConfigurationImpl) execution.getProcessEngine().getProcessEngineConfiguration()).getExpressionManager();

        Expression expression = expressionManager.createExpression(exp1);
        Object value = expression.getValue(execution);
        log.info("exp1: {}, value: {}", exp1, value);

        Expression expression2 = expressionManager.createExpression(exp2);
        Object value2 = expression2.getValue(execution);
        log.info("exp2: {}, value: {}", exp2, value2);

    }

}
